package com.app.service.adapter;

import java.util.ArrayList;

import com.app.activity.R;
import com.app.data.InnItem;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class HotelAdapter extends DataAdapter 
{
	private ArrayList<InnItem> hotels;
	public HotelAdapter(Activity parentActivity ,ArrayList<InnItem> hotels)
	{
		this(parentActivity);
		this.hotels = hotels;
	}

	public HotelAdapter(Activity parentActivity ) {
		super(parentActivity);
	}
	@Override
	public int getCount() {
		return hotels.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HotelHandle handle;
		if (convertView == null) {
			convertView = LayoutInflater.from(parentActivity).inflate(R.layout.inn_list_item, null);
			handle = new HotelHandle();
			handle.imgIcon = (ImageView)convertView.findViewById(R.id.imgInnIcon); 
			handle.starView = (ImageView)convertView.findViewById(R.id.imgInnStarLevel);
			handle.titleView = (TextView)convertView.findViewById(R.id.tvInnName);
			handle.contentView = (TextView)convertView.findViewById(R.id.tvInnAddress);
			handle.priceView = (TextView)convertView.findViewById(R.id.tvInnPrice);
			convertView.setTag(handle);
		}else {
			handle = (HotelHandle)convertView.getTag();
		}
		
		InnItem item = hotels.get(position);
		handle.titleView.setText(item.getName());
		handle.contentView.setText(item.getSite());
		handle.priceView.setText(item.getMoney());
		handle.imgIcon.setImageBitmap(item.getIconbitmap());	
		return convertView;
	}
	
	class HotelHandle
	{
		ImageView imgIcon;
		TextView titleView;
		TextView contentView;
		ImageView starView;
		TextView priceView;
	}
}
